]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
extensionUtils: Load extensions asynchronously
authorFlorian Müllner <fmuellner@gnome.org>
Fri, 30 Nov 2012 17:06:11 +0000 (18:06 +0100)
committerFlorian Müllner <fmuellner@gnome.org>
Wed, 5 Dec 2012 20:56:21 +0000 (21:56 +0100)
Use the new collectFromDatadirsAsync() function for extension
loading as well.

https://bugzilla.gnome.org/show_bug.cgi?id=689304

js/misc/extensionUtils.js

index 14be194ef5871c22078f6bfdab5891dff85bd94a..9e70e265fc155c1df9f2b6f0f76aeb3da2098dbd 100644 (file)
@@ -11,6 +11,7 @@ const Gio = imports.gi.Gio;
 const ShellJS = imports.gi.ShellJS;
 
 const Config = imports.misc.config;
+const FileUtils = imports.misc.fileUtils;
 
 const ExtensionType = {
     SYSTEM: 1,
@@ -150,53 +151,35 @@ function installImporter(extension) {
 const ExtensionFinder = new Lang.Class({
     Name: 'ExtensionFinder',
 
-    _scanExtensionsInDirectory: function(dir, type) {
-        let fileEnum;
-        let file, info;
-        try {
-            fileEnum = dir.enumerate_children('standard::*', Gio.FileQueryInfoFlags.NONE, null);
-        } catch(e) {
-            if (e.domain != Gio.io_error_quark() || e.code != Gio.IOErrorEnum.NOT_FOUND)
-                logError(e, 'Could not enumerate extensions directory');
+    _loadExtension: function(extensionDir, info, perUserDir) {
+        let fileType = info.get_file_type();
+        if (fileType != Gio.FileType.DIRECTORY)
+            return;
+        let uuid = info.get_name();
+        let existing = extensions[uuid];
+        if (existing) {
+            log('Extension %s already installed in %s. %s will not be loaded'.format(uuid, existing.path, extensionDir.get_path()));
             return;
         }
 
-        while ((info = fileEnum.next_file(null)) != null) {
-            let fileType = info.get_file_type();
-            if (fileType != Gio.FileType.DIRECTORY)
-                continue;
-            let uuid = info.get_name();
-            let extensionDir = dir.get_child(uuid);
-
-            let existing = extensions[uuid];
-            if (existing) {
-                log('Extension %s already installed in %s. %s will not be loaded'.format(uuid, existing.path, extensionDir.get_path()));
-                continue;
-            }
-
-            let extension;
-            try {
-                extension = createExtensionObject(uuid, extensionDir, type);
-            } catch(e) {
-                logError(e, 'Could not load extension %s'.format(uuid));
-                continue;
-            }
-            this.emit('extension-found', extension);
+        let extension;
+        let type = extensionDir.has_prefix(perUserDir) ? ExtensionType.PER_USER
+                                                       : ExtensionType.SYSTEM;
+        try {
+            extension = createExtensionObject(uuid, extensionDir, type);
+        } catch(e) {
+            logError(e, 'Could not load extension %s'.format(uuid));
+            return;
         }
-        fileEnum.close(null);
+        this.emit('extension-found', extension);
     },
 
     scanExtensions: function() {
-        let userExtensionsDir = Gio.File.new_for_path(GLib.build_filenamev([global.userdatadir, 'extensions']));
-        this._scanExtensionsInDirectory(userExtensionsDir, ExtensionType.PER_USER);
-
-        let systemDataDirs = GLib.get_system_data_dirs();
-        for (let i = 0; i < systemDataDirs.length; i++) {
-            let dirPath = GLib.build_filenamev([systemDataDirs[i], 'gnome-shell', 'extensions']);
-            let dir = Gio.file_new_for_path(dirPath);
-            if (dir.query_exists(null))
-                this._scanExtensionsInDirectory(dir, ExtensionType.SYSTEM);
-        }
+        let perUserDir = Gio.File.new_for_path(global.userdatadir);
+        FileUtils.collectFromDatadirsAsync('extensions',
+                                           { processFile: Lang.bind(this, this._loadExtension),
+                                             includeUserDir: true,
+                                             data: perUserDir });
     }
 });
 Signals.addSignalMethods(ExtensionFinder.prototype);